package com.jhoncy.rapid.base.service.serviceImpl;

import com.jhoncy.rapid.base.bean.UserInfo;
import com.jhoncy.rapid.base.bo.BaseUserStatusEnum;
import com.jhoncy.rapid.base.pojo.BaseUser;
import com.jhoncy.rapid.base.repository.BaseUserRepository;
import com.jhoncy.rapid.base.service.BaseUserService;
import com.jhoncy.rapid.kit.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class BaseUserServiceImpl implements BaseUserService{

    @Autowired
    private BaseUserRepository baseUserRepository;

    @Autowired
    private Md5PasswordEncoder md5PasswordEncoder;

    @Override
    public void saveBaseUser(BaseUser baseUser) {
        baseUser.setUserId(UUID.UU64());
        baseUser.setPassword(md5PasswordEncoder.encodePassword(baseUser.getPassword(),null));
        baseUser.setInsertUser(UserInfo.getUserId());
        baseUser.setInsertDate(new Date());
        baseUser.setStatus(BaseUserStatusEnum.NORMAL.Opt());
        baseUserRepository.save(baseUser);
    }

    @Override
    public BaseUser findBaseUserByUserName(String userName) {
        return baseUserRepository.findBaseUserByUserName(userName);
    }

}
